package org.benxiong.iplay.util;

import android.content.Context;
import android.content.SharedPreferences;

public class PreferencesUtil {
	public static final String LOGIN_INFO = "login_info";
	public static final String PASSWORD = "password";
	public static final String USERNAME = "userName";
	
	//GCM register preferences
	public static final String GCM_REG_INFO = "gcm_reg_info";
	public static final String GCM_KEY_ISREGOK = "is_reg_ok";
	
	/**
	 * save user login information
	 * @param userName
	 * @param password
	 */
	public static void saveLoginInfo(String userName, String password) {
		SharedPreferences sp = GlobalVar.appContext.getSharedPreferences(LOGIN_INFO, Context.MODE_PRIVATE);
		sp.edit().putString(USERNAME, userName).putString(PASSWORD, password).commit();
	}
	
	public static boolean isLogin() {
		SharedPreferences sp = GlobalVar.appContext.getSharedPreferences(LOGIN_INFO, Context.MODE_PRIVATE);
		if(sp.contains(USERNAME)) {
			return true;
		}
		
		return false;
	}
	
	public static void logout() {
		SharedPreferences sp = GlobalVar.appContext.getSharedPreferences(LOGIN_INFO, Context.MODE_PRIVATE);
		sp.edit().clear().commit();
	}
	
	public static SharedPreferences getLoginInfo() {
		SharedPreferences sp = GlobalVar.appContext.getSharedPreferences(LOGIN_INFO, Context.MODE_PRIVATE);
		return sp;
	}
	
	public static void saveGCMRegInfo() {
		SharedPreferences sp = GlobalVar.appContext.getSharedPreferences(GCM_REG_INFO, Context.MODE_PRIVATE);
		sp.edit().putBoolean(GCM_KEY_ISREGOK, true).commit();
	}
	
	public static boolean isGCMRegSuccess() {
		SharedPreferences sp = GlobalVar.appContext.getSharedPreferences(GCM_REG_INFO, Context.MODE_PRIVATE);
		return sp.getBoolean(GCM_KEY_ISREGOK, false);
	}
}
